package com.itheima.ithmshortlink.controller;

import com.itheima.ithmshortlink.dto.LongLink;
import com.itheima.ithmshortlink.result.Result;
import com.itheima.ithmshortlink.service.ShortLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @description:   写代码步骤:
 *                  //TODO log, 日志
 *                  //TODO validate, 验证
 *                 //TODO  handle business , 处理业务
 *                 //TODO
 *                 //TODO response ,  相应结果
 * @author: 龙宇
 * @date: 2021/7/4
 */




@RestController
@RequestMapping("/api/v1")
public class ShortLinkController {


    @Autowired
    private ShortLinkService shortLinkService;

    /**
     * @description: 将前段传递过来的url转换成短链响应给前端
     * @author: 龙宇
     * @date: 2021/7/3 : 20:54
     * @params: null:
     * @return: null
     */
    @RequestMapping("/create")
    public Result toShortLink(@RequestBody LongLink longLink) {

        String shortLink = shortLinkService.toShortLink(longLink);
        return new Result("提交成功!!!",shortLink);
    }



    /**
     * @description: 短链状态修改
     * @author: 龙宇
     * @date: 2021/7/4 : 0:30
     * @params: null:
     * @return: null
     */
    @RequestMapping("/{short_url}/{status}")
    public Result updateShortLinkStatus(@PathVariable("shortUrl") String shortUrl,@PathVariable("status") Integer status ){


        return new Result();
    }
}
